package com.zbc.controller.admin;

import com.zbc.dto.DishDTO;
import com.zbc.dto.DishPageDTO;
import com.zbc.result.PageResult;
import com.zbc.result.Result;
import com.zbc.service.DishService;
import com.zbc.vo.DishVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/dish")
@Api(tags = "菜品相关接口")
public class DishController {

    @Autowired
    private DishService dishService;

    @GetMapping("/page")
    @ApiOperation("菜品分页信息")
    public Result<PageResult> page(DishPageDTO dishPageDTO){
        PageResult pageResult = dishService.page(dishPageDTO);
        return Result.success(pageResult);
    }

    @PostMapping()
    @ApiOperation("添加菜品")
    public Result save(@RequestBody DishDTO dishDTO){
        System.out.println(dishDTO);
        dishService.addDish(dishDTO);
        return Result.success();
    }

    @PostMapping("/status/{status}")
    @ApiOperation("启用停售菜品")
    public Result updateStatus(@PathVariable("status") Integer status,Integer id){
        dishService.updateStatus(status,id);
        return Result.success();
    }

    @DeleteMapping()
    @ApiOperation("删除菜品")
    public Result delete(Integer[] ids){
        dishService.deleteDish(ids);
        return Result.success();
    }

    @GetMapping("/{id}")
    @ApiOperation("获取菜品详情")
    public Result<DishVo> getById(@PathVariable("id") Integer id){
        DishVo dishVo = dishService.fetchByIdDishInfo(id);
        return Result.success(dishVo);
    }

    @PutMapping()
    @ApiOperation("修改菜品信息")
    public Result update(@RequestBody DishDTO dishDTO){
        dishService.updateDishInfo(dishDTO);
        return Result.success();
    }
}
